package com.xuxueli.commontdemo.util;

import com.google.common.collect.Lists;

import java.sql.Types;
import java.util.List;

/**
 * jdbc类型分组
 */
public class JdbcTypeUtils {

    private final static List<Integer> NUMBER_LIST = Lists.newArrayList(Types.BIGINT, Types.DECIMAL, Types.DOUBLE, Types.FLOAT, Types.INTEGER, Types.NUMERIC, Types.SMALLINT, Types.TINYINT);

    private final static List<Integer> STRING_LIST = Lists.newArrayList(Types.CHAR, Types.VARCHAR, Types.BLOB, Types.CLOB, Types.LONGNVARCHAR, Types.LONGVARBINARY, Types.LONGVARCHAR, Types.NCHAR, Types.NCLOB);

    private final static List<Integer> LOB_LIST = Lists.newArrayList(Types.BLOB, Types.CLOB,Types.LONGVARBINARY, Types.NCLOB,Types.BINARY,Types.VARBINARY);

    private final static List<Integer> DATE_LIST = Lists.newArrayList(Types.DATE, Types.TIME, Types.TIME_WITH_TIMEZONE, Types.TIMESTAMP, Types.TIMESTAMP_WITH_TIMEZONE);

    private final static List<Integer> INT_LIST = Lists.newArrayList(Types.INTEGER, Types.NUMERIC, Types.SMALLINT, Types.TINYINT);

    private final static List<Integer> DOUBLE_LIST = Lists.newArrayList(Types.DECIMAL, Types.DOUBLE, Types.FLOAT);

    private final static List<Integer> LONG_LIST = Lists.newArrayList(Types.BIGINT);

    public static final boolean isNumber(int dataType) {
        return NUMBER_LIST.indexOf(dataType) != -1;
    }

    public static final boolean isString(int dataType) {
        return STRING_LIST.indexOf(dataType) != -1;
    }

    public static final boolean isLob(int dataType) {
        return LOB_LIST.indexOf(dataType) != -1;
    }

    public static final boolean isDate(int dataType) {
        return DATE_LIST.indexOf(dataType) != -1;
    }

    public static final boolean isInt(int dataType) {
        return INT_LIST.indexOf(dataType) != -1;
    }

    public static final boolean isDouble(int dataType) {
        return DOUBLE_LIST.indexOf(dataType) != -1;
    }

    public static final boolean isLong(int dataType) {
        return LONG_LIST.indexOf(dataType) != -1;
    }

}
